
private boolean authenticate() throws SQLException {
    String dbUrl = "jdbc:mysql://"; //Please Enter the URL

    // This query will simply count the matching rows, instead of 
    // actually selecting them. This will result in less bandwidth  
    // between your application and the server
    String query = "SELECT count(*) AS num_records FROM student WHERE username = ? AND password = ?";

    // Obtaining the username and password beforehand could
    // perhaps make it more clear and prevent errors instead 
    // of pulling the data every time you need it
    String username = txtUser.getText();
    String password = txtPass.getText();

    // The try-with-resources block will make sure the resources  
    // are closed once we are done with them.
    try (
        // Open database connection
        Connection conn = DriverManager.getConnection(dbUrl,
        	 "root", "jesus");

        // Prepare the statement
        PreparedStatement stmt = conn.prepareStatement(query)
    ) {
        // Set the username and password for the SQL statement
        stmt.setString(1, username);
        stmt.setString(2, password);

        // Execute the query in a try block, to ensure that the 
        // resources will be released
        try (ResultSet rs = stmt.executeQuery()) {
            if (rs.next()) {
                // If we got 1 or more matches, this means we successfully
                // authenticated. Otherwise, we failed authentication.
                return rs.getInt("num_records") > 0;
            }
        }
    }

    // Failed authentication.
    return false;
}

private void doAuthentication() {
    try {
        if (authenticate()) {
            // Do successful authentication handling
            this.dispose();
            new AboutTo().setVisible(true);
        } else {
            // Do failed authentication handling
            JOptionPane.showMessageDialog(null,
            	"Invalid Username or Password");
        }
    } catch(SQLException er) {
        // Do error handling
        JOptionPane.showMessageDialog(null,
        	"Exception:\n" + er.toString());
    }
}